package cn.gjculture.shopping.api.controller;

import cn.gjculture.shopping.api.entity.Logistics;
import cn.gjculture.shopping.api.entity.Return;
import cn.gjculture.shopping.api.service.LogisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/logistics")
public class LogisticsController {

    @Autowired
    LogisticsService logisticsService;

    @PostMapping
    public Return save(Logistics logistics, String orderType, Return ret){
        logisticsService.insert(logistics,orderType);
        ret.getCommon().setRet(true);
        return ret;
    }


    @GetMapping(value = "/{goodsRecordId}")
    public Return<List<Logistics>> queryByOrderId(@PathVariable(value = "goodsRecordId") String goodsRecordId){
        Return<List<Logistics>> ret=new Return<>();
        List<Logistics>  logisticsList=logisticsService.queryByGoodsRecordId(goodsRecordId);
        if(logisticsList!=null&&logisticsList.size()>0){
            ret.setData(logisticsList);
            ret.getCommon().setRet(true);
        }
        return ret;
    }
    @DeleteMapping(value = "/{logisticsId}")
    public Return delete(@PathVariable(value = "logisticsId") String logisticsId){
        Return ret=new Return();
        if(logisticsService.delete(logisticsId)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }

}
